package cn.javadog.ss.spring.ioc.applicationcontext;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * @author 余勇
 * @date 2019年11月24日 18:31:00
 * 1. 四种注入类型
 * 2. 启动流程
 * 3. 事件
 */
public class ApplicationContextBootstrap {

	private static final String APPLICATIONCONTEXT_INJECT_XML_CLASSPATH = "applicationContextTest.xml";
	private static final String APPLICATIONCONTEXT_PROCESS_XML_CLASSPATH = "applicationContextTest2.xml";
	private static final String BEANPOSTPROCESSOR_XML_CLASSPATH = "xmlBeanPostProcessorTest.xml";

	private static void printSeparator() {
		System.out.println("<============= NEXT TEST =============>");
	}

	public static void main(String[] args) {
		// 启动流程
//		ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext(APPLICATIONCONTEXT_PROCESS_XML_CLASSPATH);
//		printSeparator();
//		ComplexBean contextBean = applicationContext.getBean(ComplexBean.class);
//		printSeparator();
//		applicationContext.close();

		// 四种注入类型
		// injectTest(applicationContext);

		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(BEANPOSTPROCESSOR_XML_CLASSPATH);
		XmlBeanPostProcessorTestBean bean = context.getBean(XmlBeanPostProcessorTestBean.class);
		SimpleBean simpleBean = context.getBean(SimpleBean.class);
		bean.display();
		simpleBean.sayHi();

	}

	/**
	 * 1. 四种注入类型
	 */
	public static void injectTest(ApplicationContext applicationContext) {
		// 构造器注入
		ConstructorInjectBean constructorInjectBean = applicationContext.getBean(ConstructorInjectBean.class);
		printSeparator();

		// setter注入
		PropertyInjectBean propertyInjectBean = applicationContext.getBean(PropertyInjectBean.class);
		System.out.println(propertyInjectBean);
		printSeparator();

		// 接口注入 note 很扯

		// 注解字段注入
		AnnotationBean annotationBean = applicationContext.getBean(AnnotationBean.class);
		System.out.println("annotationBean: " + annotationBean.result());
		printSeparator();
	}

	/**
	 * 启动流程
	 */
	public static void initProcessTest(ApplicationContext applicationContext){

	}
}
